package com.ruoyi.web.controller.rjgc;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.littleRedBook.domain.pojo.Product;
import com.ruoyi.littleRedBook.service.AdminProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/admin/product")
@Api(tags = "管理端-商品审核")
public class AdminProductController {

    @Autowired
    private AdminProductService adminProductService;

    @GetMapping("/pending")
    @ApiOperation("获取待审核商品列表")
    public AjaxResult getPendingProducts(
            @ApiParam("页码，默认1") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("每页条数，默认10") @RequestParam(defaultValue = "10") Integer pageSize) {
        return adminProductService.getPendingProducts(pageNum, pageSize);
    }

    @PutMapping("/approve/{id}")
    @ApiOperation("审核通过商品")
    public AjaxResult approveProduct(@ApiParam("商品ID") @PathVariable Long id) {
        return adminProductService.approveProduct(id);
    }

    @PutMapping("/reject/{id}")
    @ApiOperation("审核驳回商品")
    public AjaxResult rejectProduct(
            @ApiParam("商品ID") @PathVariable Long id,
            @ApiParam("驳回原因") @RequestParam String rejectReason) {
        return adminProductService.rejectProduct(id, rejectReason);
    }

    @GetMapping("/approved")
    @ApiOperation("获取已审核商品列表（可筛选状态）")
    public AjaxResult getApprovedProducts(
            @ApiParam("商品状态：1-审核通过 2-审核驳回 3-已下架 4-已售出") @RequestParam Integer status,
            @ApiParam("页码，默认1") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("每页条数，默认10") @RequestParam(defaultValue = "10") Integer pageSize) {
        return adminProductService.getApprovedProducts(status, pageNum, pageSize);
    }
}
